/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jse.concurrent;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * CurrentThread静态方法获得当前线程
 * 在线程中使用throw抛出异常，在外部线程中使用try catch并不能捕获,仍会抛出异常
 * 
 * @author WangShuai
 */
public class CatchException extends Thread {

    public void run() {
        System.out.println("Current Thread:" + Thread.currentThread());  //Current Thread:Thread[pool-1-thread-1,5,main]
        throw new RuntimeException();
    }

    public static void main(String[] args) {
        try {
            System.out.println("Current Thread:" + Thread.currentThread());  //Current Thread:Thread[main,5,main]
            ExecutorService exec = Executors.newCachedThreadPool();
            exec.execute(new CatchException());
        } catch (Exception e) {
            System.out.println("Catch Exception");
        }
    }

    //Exception Catch Handler
    class ExcpetionCatchHandler implements Thread.UncaughtExceptionHandler {

        public void uncaughtException(Thread t, Throwable e) {
            System.out.println("Catch Exception " + e);
        }

    }
}
